import { CustomForm } from "@/components/ProForm/interface";
export const useForm = () => {
  const addForm = reactive<CustomForm>({
    // 是否可编辑
    editable: true,
    save: () => null,
    form: {
      newPassword: "",
      oldPassword: "",
      username: ""
    },
    options: [
      {
        type: "title",
        label: "基础信息",
        hide: false
      },
      {
        type: "input",
        label: "账号",
        prop: "username",
        hide: false,
        attrs: {
          disabled: true,
          clearable: true
        },
        rules: [
          {
            required: true,
            errorMessage: "用户名称不能为空"
          }
        ]
      },
      {
        type: "input",
        label: "旧密码",
        prop: "oldPassword",
        hide: false,
        attrs: {
          disabled: false,
          clearable: true,
          type: "password"
        },
        rules: [
          {
            required: true,
            errorMessage: "旧密码不能为空"
          }
        ]
      },
      {
        type: "input",
        label: "新密码",
        hide: false,
        prop: "newPassword",
        attrs: {
          disabled: false,
          clearable: true,
          type: "password"
        },
        rules: [
          {
            required: true,
            errorMessage: "新密码不能为空"
          }
        ]
      }
    ]
  });

  const submitForm = async form => {
    await paramsUpPasswordByUser(form);
    useGlobalStore().setMessage();
    setTimeout(() => {
      uni.reLaunch({
        url: "/pages/login/index"
      });
    }, 500);
  };

  return {
    addForm,
    submitForm
  };
};
